import Vue from 'vue'
import {fetch, put, post, del} from "./baseApi";

Vue.prototype.$fetch = fetch
Vue.prototype.$put = put
Vue.prototype.$post = post
Vue.prototype.$delete = del
export const getRightsList = (url) => {
  return Vue.prototype.$fetch("rights/list")
}

export const getRolesList = (url) => {
  return Vue.prototype.$fetch("roles")
}

export const addRoles = (payload) => {
  return Vue.prototype.$post("roles", payload)
}

export const getRolesById = (id) => {
  return Vue.prototype.$fetch("roles/" + id)
}

export const deleteRolesById = (id) => {
  return Vue.prototype.$delete("roles/" + id)
}

export const updateRoles = (payload) => {
  console.log(payload);
  return Vue.prototype.$put("roles/" + payload.id, payload.roles)
}

export const removeRightById = (payload) => {
  let url = "roles/" + payload.roleId + "/rights/" + payload.rightId
  return Vue.prototype.$delete(url)
}

export const getRightsTree = (url) => {
  return Vue.prototype.$fetch("rights/tree")
}

export const allotRights = (payload) => {
  console.log(payload);
  return Vue.prototype.$post("roles/" + payload.id + "/rights", payload.rids)
}



